package com.lehecai.core.task.sender.validator.impl;

import com.lehecai.core.task.IAsyncTask;
import com.lehecai.core.task.sender.validator.AbstractAsyncTaskSenderValidator;
import org.apache.commons.lang.StringUtils;

/**
 * Created by qatang on 14-3-26.
 */
public class CommonAsyncTaskSenderValidator extends AbstractAsyncTaskSenderValidator {
    @Override
    protected boolean validateTask(IAsyncTask asyncTask) throws Exception {
        if (asyncTask == null) {
            String errorMsg = "通用异步任务发送验证器 验证失败：asyncTask参数不能为空";
            logger.error(errorMsg);
            throw new Exception(errorMsg);
        }

        if (asyncTask.getAsyncTaskType() == null) {
            String errorMsg = "通用异步任务发送验证器 验证失败：asyncTaskType不能为空";
            logger.error(errorMsg);
            throw new Exception(errorMsg);
        }

        if (StringUtils.isEmpty(asyncTask.getName())) {
            String errorMsg = "通用异步任务发送验证器 验证失败：name不能为空";
            logger.error(errorMsg);
            throw new Exception(errorMsg);
        }

        return true;
    }
}
